package com.vx.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.vx.ratingTool.SelectedPlayer;
import com.vx.ratingTool.bo.PlayerBOimpl;
import com.vx.ratingTool.dao.PlayerDAOimpl;

@Controller
@RequestMapping("/selectPlayer")
public class selectPlayerController {

	private PlayerDAOimpl playerDAO;
	private PlayerBOimpl playerBO;
	private SelectedPlayer selected_player;

	public PlayerDAOimpl getPlayerDAOimpl() {
		return playerDAO;
	}

	@Autowired
	public void setPlayerDAOimpl(PlayerDAOimpl playerDAO) {
		this.playerDAO = playerDAO;
	}

	public PlayerBOimpl getPlayerBO() {
		return playerBO;
	}

	@Autowired
	public void setPlayerBO(PlayerBOimpl playerBO) {
		this.playerBO = playerBO;
	}

	// private SessionFactory sessionFactory;

	@RequestMapping(method = RequestMethod.GET)
	public void SetupForm(Model model) {
		if (selected_player.getId() != -1)
			model.addAttribute("selected", "Selected player: " + playerBO.findById(selected_player.getId()).getName());
		else {
			model.addAttribute("selected", "Selected player: none");
		}
	}

	@RequestMapping(method = RequestMethod.POST)
	public String CreatePlayers(@RequestParam("id") int id, Model model) {
		selected_player.setId(id);
		model.addAttribute("selected", "Selected player: " + playerBO.findById(selected_player.getId()).getName());

		return "selectPlayer";
	}

	public SelectedPlayer getPlayer() {
		return selected_player;
	}

	@Autowired
	public void setPlayer(SelectedPlayer player) {
		this.selected_player = player;
	}

}
